package com.seeyon.apps.ebs.rc.manager.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.collaboration.manager.ColManager;
import com.seeyon.apps.ebs.rc.dao.RcDao;
import com.seeyon.apps.ebs.rc.info.RcUserInfo;
import com.seeyon.apps.ebs.rc.manager.RcManager;
import com.seeyon.apps.ebs.rc.utils.RcMemberSortUtils;
import com.seeyon.apps.ebs.rc.utils.RcUtils;
import com.seeyon.cap4.form.api.FormApi4Cap4;
import com.seeyon.cap4.form.bean.FormBean;
import com.seeyon.cap4.form.bean.FormFieldBean;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.authenticate.domain.User;
import com.seeyon.ctp.common.ctpenumnew.manager.EnumManager;
import com.seeyon.ctp.common.template.manager.TemplateManager;
import com.seeyon.ctp.organization.bo.V3xOrgAccount;
import com.seeyon.ctp.organization.bo.V3xOrgDepartment;
import com.seeyon.ctp.organization.bo.V3xOrgMember;
import com.seeyon.ctp.organization.manager.OrgManager;
import com.seeyon.ctp.util.JDBCAgent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class RcManagerImpl implements RcManager {
    private static final Log log = LogFactory.getLog(RcManagerImpl.class);
    private static ColManager colManager = (ColManager) AppContext.getBean("colManager");
    private static EnumManager enumManager = (EnumManager) AppContext.getBean("enumManagerNew");
    private static OrgManager orgManager = (OrgManager) AppContext.getBean("orgManager");
    private static FormApi4Cap4 cap4FormManager = (FormApi4Cap4) AppContext.getBean("formApi4Cap4");
    private static TemplateManager templateManager = (TemplateManager) AppContext.getBean("templateManager");
    private static RcDao rcDao = (RcDao) AppContext.getBean("ebsRcDao");
    private static SimpleDateFormat adf = new SimpleDateFormat("yyyy-MM-dd");
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    private static String scheduleArchiveCode = AppContext.getSystemProperty("ebsRc.scheduleArchiveCode");
    private static String deptWeihuCode = AppContext.getSystemProperty("ebsRc.deptWeihuCode");
    private Map<String,String> typeMap = new HashMap<String,String>(){
        {
            put("1","Jan");
            put("2","Feb");
            put("3","Mar");
            put("4","Apr");
            put("5","May");
            put("6","Jun");
            put("7","Jul");
            put("8","Aug");
            put("9","Sep");
            put("10","Oct");
            put("11","Nov");
            put("12","Dec");
        }
    };


    public static JDBCAgent getJdbcAgent() throws Exception{
        JDBCAgent jdbcAgent = new JDBCAgent(false,false);
        return jdbcAgent;
    }

    public void closeJdbcAgent(JDBCAgent jdbcAgent) throws Exception{
        if (jdbcAgent != null) {
            jdbcAgent.close();
        }
    }


    @Override
    public JSONObject leadershipAgendaDepartment(JSONObject param)throws Exception {
        JSONObject dataJson = new JSONObject();
        LocalDate now = LocalDate.now();
        long zOnSite = 0;
        long zBt = 0;
        long zRl = 0;
        V3xOrgMember member = orgManager.getMemberById(param.getLong("userId"));
        JSONObject jsonObject = RcUtils.personalScheduleRoles(member.getId());
        if (jsonObject != null && !jsonObject.isEmpty()){
            Integer grade = jsonObject.getInteger("grade");
            if (grade != null && grade != 0 && grade != 3){
                JDBCAgent jdbcAgent = getJdbcAgent();
                JSONArray monthJa = new JSONArray();
                if (grade == 1){//总
                    V3xOrgAccount account = orgManager.getAccountById(member.getOrgAccountId());//orgAccountId
                    Map<String,Object> depSqlMap = new HashMap<>();
                    depSqlMap.put("orgAccountId", account.getId());
                    //使用部门维护表的部门
                    List<Map<String, Object>> departments = rcDao.getAllNeedDept();
                    //List<Map<String, Object>> departments = rcDao.getAllDepartmentByAccountId(depSqlMap);
                    if (departments != null){
                        for (Map<String, Object> department : departments){
                            JSONObject depDqJson = new JSONObject();
                            Long depId = Long.valueOf(department.get("id").toString());
                            V3xOrgDepartment v3xOrgDepartment = orgManager.getDepartmentById(depId);
                            JSONObject depCxJson = new JSONObject();
                            JSONArray depIds = new JSONArray();
                            depIds.add(v3xOrgDepartment.getId());
                            depCxJson.put("depIds", depIds);
                            depCxJson.put("dqDate", now.toString());
                            depDqJson.put("deptName",department.get("jc"));
                            depDqJson.put("deptId", v3xOrgDepartment.getId());
                            depDqJson.put("bt",0);
                            depDqJson.put("onSite",0);
                            depDqJson.put("rl",0);
                            List<Map<String, Object>> allPeopleEbsRc = rcDao.getAllPeopleEbsRc(depCxJson);
                            if (allPeopleEbsRc!=null && allPeopleEbsRc.size()>0){
                                for (Map<String, Object> peopleEbsRcMap : allPeopleEbsRc){
                                    Object stateObj = peopleEbsRcMap.get("state");
                                    if (stateObj!=null){
                                        Object lsObj = peopleEbsRcMap.get("sl");
                                        if ("1".equals(stateObj.toString()) || "4".equals(stateObj.toString())){
                                            Integer ls = Integer.valueOf(lsObj.toString());
                                            depDqJson.put("bt",ls);
                                            zBt+=ls;
                                        }else if ("2".equals(stateObj.toString())){
                                            Integer ls = Integer.valueOf(peopleEbsRcMap.get("sl").toString());
                                            depDqJson.put("onSite",ls);
                                            zOnSite+=ls;
                                        } else if ("3".equals(stateObj.toString())) {
                                            Integer ls = Integer.valueOf(peopleEbsRcMap.get("sl").toString());
                                            depDqJson.put("rl",ls);
                                            zRl+=ls;
                                        }
                                    }
                                }
                            }
                            monthJa.add(depDqJson);
                        }
                    }
                }else if(grade == 2){//分管、主管
                    JSONArray zgDepId = jsonObject.getJSONArray("zgDepId");
                    JSONObject zgDepIdName = jsonObject.getJSONObject("zgDepIdName");
                    for (Object depId : zgDepId) {
                        JSONObject depDqJson = new JSONObject();
                        JSONObject depCxJson = new JSONObject();
                        V3xOrgDepartment department = orgManager.getDepartmentById(Long.valueOf(depId.toString()));
                        // depCxJson.put("deptId", department.getId());
                        // depCxJson.put("now", now.toString());
                        JSONArray depIds = new JSONArray();
                        depIds.add(department.getId());
                        depCxJson.put("depIds", depIds);
                        depCxJson.put("dqDate", now.toString());
                        depDqJson.put("deptName",zgDepIdName.get(depId.toString()));
                        depDqJson.put("deptId", department.getId());
                        depDqJson.put("bt",0);
                        depDqJson.put("onSite",0);
                        depDqJson.put("rl",0);
                        List<Map<String, Object>> allPeopleEbsRc = rcDao.getAllPeopleEbsRc(depCxJson);
                        if (allPeopleEbsRc!=null && allPeopleEbsRc.size()>0){
                            for (Map<String, Object> peopleEbsRcMap : allPeopleEbsRc){
                                Object stateObj = peopleEbsRcMap.get("state");
                                if (stateObj!=null){
                                    Object lsObj = peopleEbsRcMap.get("sl");
                                    if ("1".equals(stateObj.toString()) || "4".equals(stateObj.toString())){
                                        Integer ls = Integer.valueOf(lsObj.toString());
                                        depDqJson.put("bt",ls);
                                        zBt+=ls;
                                    }else if ("2".equals(stateObj.toString())){
                                        Integer ls = Integer.valueOf(peopleEbsRcMap.get("sl").toString());
                                        depDqJson.put("onSite",ls);
                                        zOnSite+=ls;
                                    } else if ("3".equals(stateObj.toString())) {
                                        Integer ls = Integer.valueOf(peopleEbsRcMap.get("sl").toString());
                                        depDqJson.put("rl",ls);
                                        zRl+=ls;
                                    }
                                }
                            }
                        }
                        // JSONObject deptDqJson = RcUtils.personalSchedule(depCxJson,jdbcAgent);
                        // Long onSite = deptDqJson.getLong("onSite");
                        // Long bt = deptDqJson.getLong("bt");
                        // Long rl = deptDqJson.getLong("rl");
                        // depDqJson.put("onSite", onSite);
                        // depDqJson.put("bt",bt);
                        // depDqJson.put("rl",rl);
                        // zOnSite+=onSite;
                        // zBt+=bt;
                        // zRl+=rl;
                        monthJa.add(depDqJson);
                    }
                }
                dataJson.put("onSite", zOnSite);
                dataJson.put("bt", zBt);
                dataJson.put("rl", zRl);
                dataJson.put("allStaff", monthJa);
                closeJdbcAgent(jdbcAgent);
            }
        }
        log.info("领导日程部门信息");
        return dataJson;
    }

    @Override
    public JSONObject handleDepartmentClick(JSONObject param) throws Exception {
        JSONObject dataJson = new JSONObject();
        LocalDate now = LocalDate.now();
        Integer year = param.getInteger("year");
        Long userId = param.getLong("userId");
        // Integer state = param.getInteger("state");
        Integer page = param.getInteger("page");
        Integer limit = param.getInteger("limit");
        Long deptId = param.getLong("deptId");
        JSONObject range = RcUtils.getRange(page, limit);
        dataJson.put("userId",userId);
        dataJson.put("year",year);
        Long startRange = range.getLong("start");
        Long endRange = range.getLong("end");
        long countNum = 0;//返回人员数据条数
        Integer sortType = param.getInteger("sortType");
        String sortMonth = param.getString("sortMonth");
        boolean ifSort = false;
        if (sortType != null && !"".equals(sortType) && sortMonth!=null && !"".equals(sortMonth)){//排序计算
            ifSort = true;
        }
        V3xOrgMember member = orgManager.getMemberById(userId);
        V3xOrgDepartment department = orgManager.getDepartmentById(deptId);
        if (department != null){
            JDBCAgent jdbcAgent = getJdbcAgent();
            List<RcUserInfo> memberDqJa = new ArrayList<>();
            //List<OrgMember> allMembers = rcDao.getAllMemberByDepId(department.getId());
            List<Map<String, Object>> realDeptMembers = rcDao.getRealDeptMembers(department.getId());
            List<V3xOrgMember> allMembers = new ArrayList<>();
            for (Map<String, Object> map : realDeptMembers){
                long memberId = Long.parseLong(String.valueOf(map.get("id")));
                allMembers.add(orgManager.getMemberById(memberId));
            }
            for (V3xOrgMember orgMember : allMembers) {
                countNum++;
                if (!ifSort){
                    if (countNum >= startRange && countNum <= endRange){
                        int toDayState = RcUtils.personalSchedule(now.toString(), orgMember.getId(),jdbcAgent);
                        RcUserInfo rcUserInfo = new RcUserInfo();
                        rcUserInfo.setUserName(orgMember.getName());
                        rcUserInfo.setUserId(orgMember.getId());
                        JSONObject rcJson = new JSONObject();
                        rcJson.put("year",year);
                        rcJson.put("userId",orgMember.getId());
                        JSONObject memberMonthJson = personalSchedule(rcJson);
                        JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                        rcUserInfo.setState(toDayState);
                        if (toDayState<=0){
                            rcUserInfo.setState(2);
                        }
                        rcUserInfo.setMonthInfo(monthDatas);
                        memberDqJa.add(rcUserInfo);
                    }
                }else{
                    int toDayState = RcUtils.personalSchedule(now.toString(), orgMember.getId(),jdbcAgent);
                    RcUserInfo rcUserInfo = new RcUserInfo();
                    rcUserInfo.setUserName(orgMember.getName());
                    rcUserInfo.setUserId(orgMember.getId());
                    JSONObject rcJson = new JSONObject();
                    rcJson.put("year",year);
                    rcJson.put("userId",orgMember.getId());
                    JSONObject memberMonthJson = personalSchedule(rcJson);
                    JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                    rcUserInfo.setState(toDayState);
                    if (toDayState<=0){
                        rcUserInfo.setState(2);
                    }
                    rcUserInfo.setMonthInfo(monthDatas);
                    if (ifSort){
                        if (sortMonth.equals("Total")){
                            JSONObject tatal = monthDatas.getJSONObject("Total");
                            if (tatal != null && !tatal.isEmpty()){
                                int tatalOnSite = tatal.getInteger("onSite");
                                rcUserInfo.setFate(tatalOnSite);
                            }
                        }else{
                            Set<String> keySet = typeMap.keySet();
                            for (String key : keySet) {
                                String monthKey = typeMap.get(key);
                                if (sortMonth.equals(monthKey)){
                                    JSONObject monthDate = monthDatas.getJSONObject(sortMonth);
                                    if (monthDate != null && !monthDate.isEmpty()){
                                        int tatalOnSite = monthDate.getInteger("onSite");
                                        rcUserInfo.setFate(tatalOnSite);
                                    }
                                }
                            }
                        }
                    }
                    memberDqJa.add(rcUserInfo);
                }
            }
            int startDate = startRange.intValue();
            int endDate = endRange.intValue();
            if (ifSort){
                countNum = memberDqJa.size();
                if (sortType==1){
                    //降序
                    List<RcUserInfo> rcUserInfos = RcMemberSortUtils.sortByFateDesc(memberDqJa);
                    List<RcUserInfo> newUserInfos = new ArrayList<RcUserInfo>();
                    for (int i = startDate; i <= endDate; i++) {
                        int rcSize = rcUserInfos.size();
                        if (i<=rcSize){
                            newUserInfos.add(rcUserInfos.get(i-1));
                        }
                    }
                    dataJson.put("userInfo", newUserInfos);
                }else{
                    //升序
                    List<RcUserInfo> rcUserInfos = RcMemberSortUtils.sortByFateAsc(memberDqJa);
                    List<RcUserInfo> newUserInfos = new ArrayList<RcUserInfo>();
                    for (int i = startDate; i <= endDate; i++) {
                        int rcSize = rcUserInfos.size();
                        if (i<=rcSize){
                            newUserInfos.add(rcUserInfos.get(i-1));
                        }
                    }
                    dataJson.put("userInfo", newUserInfos);
                }
            }else{
                dataJson.put("userInfo", memberDqJa);
            }

            dataJson.put("countNum",countNum);
            closeJdbcAgent(jdbcAgent);
        }
        return dataJson;
    }

    @Override
    public JSONObject fuzzySearchRelocationInfo(JSONObject param) throws Exception {
        JSONObject dataJson = new JSONObject();
        LocalDate now = LocalDate.now();
        Integer year = param.getInteger("year");
        Long userId = param.getLong("userId");
        Integer state = param.getInteger("state");
        Integer page = param.getInteger("page");
        Integer limit = param.getInteger("limit");
        Long deptId = param.getLong("deptId");
        String name = param.getString("name");
        Boolean ifDepCx = param.getBoolean("ifDepCx");
        JSONObject range = RcUtils.getRange(page, limit);
        dataJson.put("userId",userId);
        dataJson.put("year",year);
        Long startRange = range.getLong("start");
        Long endRange = range.getLong("end");
        long countNum = 0;//返回人员数据条数
        Integer sortType = param.getInteger("sortType");
        String sortMonth = param.getString("sortMonth");
        boolean ifSort = false;
        if (sortType != null && !"".equals(sortType) && sortMonth!=null && !"".equals(sortMonth)){//排序计算
            ifSort = true;
        }
        V3xOrgMember member = orgManager.getMemberById(userId);
        Map<String,Object> memMhCxMap = new HashMap<>();
        if (ifDepCx){
            memMhCxMap.put("depId",deptId);
            //部门模糊查询
        }
        memMhCxMap.put("name",name);
        List<Map<String, Object>> allPeopleByName = rcDao.getAllPeopleByName(memMhCxMap);
        List<RcUserInfo> memberDqJa = new ArrayList<>();
        if (allPeopleByName != null && !allPeopleByName.isEmpty()){
            JDBCAgent jdbcAgent = getJdbcAgent();
            //筛选人员
            for (Map<String, Object> map : allPeopleByName) {
                Long emmberId = Long.valueOf(map.get("id").toString());
                V3xOrgMember orgMember = orgManager.getMemberById(emmberId);
                int toDayState = RcUtils.personalSchedule(now.toString(), orgMember.getId(),jdbcAgent);
                if (!ifDepCx){
                    if (state!=null && !"".equals(state)){
                        if (toDayState == state){
                            countNum++;
                            if (!ifSort){
                                if (countNum >= startRange && countNum <= endRange){
                                    RcUserInfo rcUserInfo = new RcUserInfo();
                                    rcUserInfo.setUserName(orgMember.getName());
                                    rcUserInfo.setUserId(orgMember.getId());
                                    JSONObject rcJson = new JSONObject();
                                    rcJson.put("year",year);
                                    rcJson.put("userId",orgMember.getId());
                                    JSONObject memberMonthJson = personalSchedule(rcJson);
                                    JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                                    rcUserInfo.setState(toDayState);
                                    if (toDayState<=0){
                                        rcUserInfo.setFate(2);
                                    }
                                    rcUserInfo.setMonthInfo(monthDatas);
                                    memberDqJa.add(rcUserInfo);
                                }
                            }else{
                                RcUserInfo rcUserInfo = new RcUserInfo();
                                rcUserInfo.setUserName(orgMember.getName());
                                rcUserInfo.setUserId(orgMember.getId());
                                JSONObject rcJson = new JSONObject();
                                rcJson.put("year",year);
                                rcJson.put("userId",orgMember.getId());
                                JSONObject memberMonthJson = personalSchedule(rcJson);
                                JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                                rcUserInfo.setState(toDayState);
                                if (toDayState<=0){
                                    rcUserInfo.setFate(2);
                                }
                                rcUserInfo.setMonthInfo(monthDatas);
                                if (ifSort){
                                    if (sortMonth.equals("Total")){
                                        JSONObject tatal = monthDatas.getJSONObject("Total");
                                        if (tatal != null && !tatal.isEmpty()){
                                            int tatalOnSite = tatal.getInteger("onSite");
                                            rcUserInfo.setFate(tatalOnSite);
                                        }
                                    }else{
                                        Set<String> keySet = typeMap.keySet();
                                        for (String key : keySet) {
                                            String monthKey = typeMap.get(key);
                                            if (sortMonth.equals(monthKey)){
                                                JSONObject monthDate = monthDatas.getJSONObject(sortMonth);
                                                if (monthDate != null && !monthDate.isEmpty()){
                                                    int tatalOnSite = monthDate.getInteger("onSite");
                                                    rcUserInfo.setFate(tatalOnSite);
                                                }
                                            }
                                        }
                                    }
                                }
                                memberDqJa.add(rcUserInfo);
                            }
                        }
                    }else{
                        countNum++;
                        if (!ifSort){
                            if (countNum >= startRange && countNum <= endRange){
                                RcUserInfo rcUserInfo = new RcUserInfo();
                                rcUserInfo.setUserName(orgMember.getName());
                                rcUserInfo.setUserId(orgMember.getId());
                                JSONObject rcJson = new JSONObject();
                                rcJson.put("year",year);
                                rcJson.put("userId",orgMember.getId());
                                JSONObject memberMonthJson = personalSchedule(rcJson);
                                JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                                rcUserInfo.setState(toDayState);
                                if (toDayState<=0){
                                    rcUserInfo.setFate(2);
                                }
                                rcUserInfo.setMonthInfo(monthDatas);
                                memberDqJa.add(rcUserInfo);
                            }
                        }else{
                            RcUserInfo rcUserInfo = new RcUserInfo();
                            rcUserInfo.setUserName(orgMember.getName());
                            rcUserInfo.setUserId(orgMember.getId());
                            JSONObject rcJson = new JSONObject();
                            rcJson.put("year",year);
                            rcJson.put("userId",orgMember.getId());
                            JSONObject memberMonthJson = personalSchedule(rcJson);
                            JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                            rcUserInfo.setState(toDayState);
                            if (toDayState<=0){
                                rcUserInfo.setFate(2);
                            }
                            rcUserInfo.setMonthInfo(monthDatas);
                            if (ifSort){
                                if (sortMonth.equals("Total")){
                                    JSONObject tatal = monthDatas.getJSONObject("Total");
                                    if (tatal != null && !tatal.isEmpty()){
                                        int tatalOnSite = tatal.getInteger("onSite");
                                        rcUserInfo.setFate(tatalOnSite);
                                    }
                                }else{
                                    Set<String> keySet = typeMap.keySet();
                                    for (String key : keySet) {
                                        String monthKey = typeMap.get(key);
                                        if (sortMonth.equals(monthKey)){
                                            JSONObject monthDate = monthDatas.getJSONObject(sortMonth);
                                            if (monthDate != null && !monthDate.isEmpty()){
                                                int tatalOnSite = monthDate.getInteger("onSite");
                                                rcUserInfo.setFate(tatalOnSite);
                                            }
                                        }
                                    }
                                }
                            }
                            memberDqJa.add(rcUserInfo);
                        }
                    }
                }else{
                    countNum++;
                    if (!ifSort){
                        if (countNum >= startRange && countNum <= endRange){
                            RcUserInfo rcUserInfo = new RcUserInfo();
                            rcUserInfo.setUserName(orgMember.getName());
                            rcUserInfo.setUserId(orgMember.getId());
                            JSONObject rcJson = new JSONObject();
                            rcJson.put("year",year);
                            rcJson.put("userId",orgMember.getId());
                            JSONObject memberMonthJson = personalSchedule(rcJson);
                            JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                            rcUserInfo.setState(toDayState);
                            if (toDayState<=0){
                                rcUserInfo.setFate(2);
                            }
                            rcUserInfo.setMonthInfo(monthDatas);
                            memberDqJa.add(rcUserInfo);
                        }
                    }else{
                        RcUserInfo rcUserInfo = new RcUserInfo();
                        rcUserInfo.setUserName(orgMember.getName());
                        rcUserInfo.setUserId(orgMember.getId());
                        JSONObject rcJson = new JSONObject();
                        rcJson.put("year",year);
                        rcJson.put("userId",orgMember.getId());
                        JSONObject memberMonthJson = personalSchedule(rcJson);
                        JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                        rcUserInfo.setState(toDayState);
                        if (toDayState<=0){
                            rcUserInfo.setFate(2);
                        }
                        rcUserInfo.setMonthInfo(monthDatas);
                        if (ifSort){
                            if (sortMonth.equals("Total")){
                                JSONObject tatal = monthDatas.getJSONObject("Total");
                                if (tatal != null && !tatal.isEmpty()){
                                    int tatalOnSite = tatal.getInteger("onSite");
                                    rcUserInfo.setFate(tatalOnSite);
                                }
                            }else{
                                Set<String> keySet = typeMap.keySet();
                                for (String key : keySet) {
                                    String monthKey = typeMap.get(key);
                                    if (sortMonth.equals(monthKey)){
                                        JSONObject monthDate = monthDatas.getJSONObject(sortMonth);
                                        if (monthDate != null && !monthDate.isEmpty()){
                                            int tatalOnSite = monthDate.getInteger("onSite");
                                            rcUserInfo.setFate(tatalOnSite);
                                        }
                                    }
                                }
                            }
                        }
                        memberDqJa.add(rcUserInfo);
                    }
                }
            }
            closeJdbcAgent(jdbcAgent);
        }
        int startDate = startRange.intValue();
        int endDate = endRange.intValue();
        if (ifSort){
            countNum = memberDqJa.size();
            if (sortType==1){
                //降序
                List<RcUserInfo> rcUserInfos = RcMemberSortUtils.sortByFateDesc(memberDqJa);
                List<RcUserInfo> newUserInfos = new ArrayList<RcUserInfo>();
                for (int i = startDate; i <= endDate; i++) {
                    int rcSize = rcUserInfos.size();
                    if (i<=rcSize){
                        newUserInfos.add(rcUserInfos.get(i-1));
                    }
                }
                dataJson.put("userInfo", newUserInfos);
            }else{
                //升序
                List<RcUserInfo> rcUserInfos = RcMemberSortUtils.sortByFateAsc(memberDqJa);
                List<RcUserInfo> newUserInfos = new ArrayList<RcUserInfo>();
                for (int i = startDate; i <= endDate; i++) {
                    int rcSize = rcUserInfos.size();
                    if (i<=rcSize){
                        newUserInfos.add(rcUserInfos.get(i-1));
                    }
                }
                dataJson.put("userInfo", newUserInfos);
            }
        }else{
            dataJson.put("userInfo", memberDqJa);
        }

        dataJson.put("countNum",countNum);
        return dataJson;
    }

    @Override
    public JSONObject leadershipAgendaPerson(JSONObject param)throws Exception  {
        JSONObject dataJson = new JSONObject();
        LocalDate now = LocalDate.now();
        Integer year = param.getInteger("year");
        Long userId = param.getLong("userId");
        Integer state = param.getInteger("state");
        Integer page = param.getInteger("page");
        Integer limit = param.getInteger("limit");
        Integer sortType = param.getInteger("sortType");
        String sortMonth = param.getString("sortMonth");
        boolean ifSort = false;
        if (sortType != null && !"".equals(sortType) && sortMonth!=null && !"".equals(sortMonth)){//排序计算
            ifSort = true;
        }
        JSONObject range = RcUtils.getRange(page, limit);
        dataJson.put("userId",userId);
        dataJson.put("year",year);
        Long startRange = range.getLong("start");
        Long endRange = range.getLong("end");
        long countNum = 0;//返回人员数据条数
        V3xOrgMember member = orgManager.getMemberById(userId);
        JSONObject jsonObject = RcUtils.personalScheduleRoles(member.getId());
        if (jsonObject != null && !jsonObject.isEmpty()) {
            Integer grade = jsonObject.getInteger("grade");
            if (grade != null && grade != 0 && grade != 3) {
                JDBCAgent jdbcAgent = getJdbcAgent();
                List<RcUserInfo> memberDqJa = new ArrayList<>();
                if (grade == 1) {//总
                    V3xOrgAccount account = orgManager.getAccountById(member.getOrgAccountId());//orgAccountId
                    /*Map<String,Object> depSqlMap = new HashMap<>();
                    depSqlMap.put("orgAccountId", account.getId());
                    List<Map<String, Object>> departments = rcDao.getAllDepartmentByAccountId(depSqlMap);*/
                    List<Map<String, Object>> departments = rcDao.getAllNeedDept();
                    if (departments != null) {
                        for (Map<String, Object> department : departments) {
                            Long depId = Long.valueOf(department.get("id").toString());
                            V3xOrgDepartment v3xOrgDepartment = orgManager.getDepartmentById(depId);
                            //List<OrgMember> allMembers = rcDao.getAllMemberByDepId(v3xOrgDepartment.getId());
                            List<Map<String, Object>> realDeptMembers = rcDao.getRealDeptMembers(depId);
                            List<V3xOrgMember> allMembers = new ArrayList<>();
                            for (Map<String, Object> map : realDeptMembers){
                                long memberId = Long.parseLong(String.valueOf(map.get("id")));
                                allMembers.add(orgManager.getMemberById(memberId));
                            }
                            for (V3xOrgMember orgMember : allMembers) {
                                int toDayState = RcUtils.personalSchedule(now.toString(), orgMember.getId(),jdbcAgent);
                                if (state!=null && !"".equals(state)){
                                    if ((toDayState == state) || (state==2 && toDayState == 0)){
                                        countNum++;
                                        if (!ifSort){
                                            if ((countNum >= startRange && countNum <= endRange)){
                                                RcUserInfo rcUserInfo = new RcUserInfo();
                                                rcUserInfo.setUserName(orgMember.getName());
                                                rcUserInfo.setUserId(orgMember.getId());
                                                JSONObject rcJson = new JSONObject();
                                                rcJson.put("year",year);
                                                rcJson.put("userId",orgMember.getId());
                                                JSONObject memberMonthJson = personalSchedule(rcJson);
                                                JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                                                rcUserInfo.setMonthInfo(monthDatas);
                                                rcUserInfo.setState(toDayState);
                                                if (toDayState<=0){
                                                    rcUserInfo.setState(2);
                                                }
                                                memberDqJa.add(rcUserInfo);
                                            }
                                        }else{
                                            RcUserInfo rcUserInfo = new RcUserInfo();
                                            rcUserInfo.setUserName(orgMember.getName());
                                            rcUserInfo.setUserId(orgMember.getId());
                                            JSONObject rcJson = new JSONObject();
                                            rcJson.put("year",year);
                                            rcJson.put("userId",orgMember.getId());
                                            JSONObject memberMonthJson = personalSchedule(rcJson);
                                            JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                                            rcUserInfo.setMonthInfo(monthDatas);
                                            if (ifSort){
                                                if (sortMonth.equals("Total")){
                                                    JSONObject tatal = monthDatas.getJSONObject("Total");
                                                    if (tatal != null && !tatal.isEmpty()){
                                                        int tatalOnSite = tatal.getInteger("onSite");
                                                        rcUserInfo.setFate(tatalOnSite);
                                                    }
                                                }else{
                                                    Set<String> keySet = typeMap.keySet();
                                                    for (String key : keySet) {
                                                        String monthKey = typeMap.get(key);
                                                        if (sortMonth.equals(monthKey)){
                                                            JSONObject monthDate = monthDatas.getJSONObject(sortMonth);
                                                            if (monthDate != null && !monthDate.isEmpty()){
                                                                int tatalOnSite = monthDate.getInteger("onSite");
                                                                rcUserInfo.setFate(tatalOnSite);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            rcUserInfo.setState(toDayState);
                                            if (toDayState<=0){
                                                rcUserInfo.setState(2);
                                            }
                                            memberDqJa.add(rcUserInfo);
                                        }
                                    }
                                }else{
                                    countNum++;
                                    if (!ifSort){
                                        if (countNum >= startRange && countNum <= endRange){

                                            RcUserInfo rcUserInfo = new RcUserInfo();
                                            rcUserInfo.setUserName(orgMember.getName());
                                            rcUserInfo.setUserId(orgMember.getId());
                                            JSONObject rcJson = new JSONObject();
                                            rcJson.put("year",year);
                                            rcJson.put("userId",orgMember.getId());
                                            JSONObject memberMonthJson = personalSchedule(rcJson);
                                            JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                                            rcUserInfo.setMonthInfo(monthDatas);
                                            rcUserInfo.setState(toDayState);
                                            if (toDayState<=0){
                                                rcUserInfo.setState(2);
                                            }
                                            memberDqJa.add(rcUserInfo);
                                        }
                                    }else{
                                        RcUserInfo rcUserInfo = new RcUserInfo();
                                        rcUserInfo.setUserName(orgMember.getName());
                                        rcUserInfo.setUserId(orgMember.getId());
                                        JSONObject rcJson = new JSONObject();
                                        rcJson.put("year",year);
                                        rcJson.put("userId",orgMember.getId());
                                        JSONObject memberMonthJson = personalSchedule(rcJson);
                                        JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                                        rcUserInfo.setMonthInfo(monthDatas);
                                        if (ifSort){
                                            if (sortMonth.equals("Total")){
                                                JSONObject tatal = monthDatas.getJSONObject("Total");
                                                if (tatal != null && !tatal.isEmpty()){
                                                    int tatalOnSite = tatal.getInteger("onSite");
                                                    rcUserInfo.setFate(tatalOnSite);
                                                }
                                            }else{
                                                Set<String> keySet = typeMap.keySet();
                                                for (String key : keySet) {
                                                    String monthKey = typeMap.get(key);
                                                    if (sortMonth.equals(monthKey)){
                                                        JSONObject monthDate = monthDatas.getJSONObject(sortMonth);
                                                        if (monthDate != null && !monthDate.isEmpty()){
                                                            int tatalOnSite = monthDate.getInteger("onSite");
                                                            rcUserInfo.setFate(tatalOnSite);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        rcUserInfo.setState(toDayState);
                                        if (toDayState<=0){
                                            rcUserInfo.setState(2);
                                        }
                                        memberDqJa.add(rcUserInfo);
                                    }
                                }
                            }
                        }
                    }
                }else if(grade == 2) {//分管、主管
                    JSONArray zgDepId = jsonObject.getJSONArray("zgDepId");
                    for (Object depId : zgDepId) {
                        V3xOrgDepartment department = orgManager.getDepartmentById(Long.valueOf(depId.toString()));
                        //List<OrgMember> allMembers = rcDao.getAllMemberByDepId(department.getId());
                        List<Map<String, Object>> realDeptMembers = rcDao.getRealDeptMembers(department.getId());
                        List<V3xOrgMember> allMembers = new ArrayList<>();
                        for (Map<String, Object> map : realDeptMembers){
                            long memberId = Long.parseLong(String.valueOf(map.get("id")));
                            allMembers.add(orgManager.getMemberById(memberId));
                        }
                        for (V3xOrgMember orgMember : allMembers) {
                            int toDayState = RcUtils.personalSchedule(now.toString(), orgMember.getId(),jdbcAgent);
                            if (state!=null && !"".equals(state)){
                                if (toDayState == state){
                                    countNum++;
                                    if (!ifSort){
                                        if (countNum >= startRange && countNum <= endRange){
                                            RcUserInfo rcUserInfo = new RcUserInfo();
                                            rcUserInfo.setUserName(orgMember.getName());
                                            rcUserInfo.setUserId(orgMember.getId());
                                            JSONObject rcJson = new JSONObject();
                                            rcJson.put("year",year);
                                            rcJson.put("userId",orgMember.getId());
                                            JSONObject memberMonthJson = personalSchedule(rcJson);
                                            JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                                            rcUserInfo.setState(toDayState);
                                            rcUserInfo.setMonthInfo(monthDatas);
                                            rcUserInfo.setState(toDayState);
                                            if (toDayState<=0){
                                                rcUserInfo.setState(2);
                                            }
                                            memberDqJa.add(rcUserInfo);
                                        }
                                    }else{
                                        RcUserInfo rcUserInfo = new RcUserInfo();
                                        rcUserInfo.setUserName(orgMember.getName());
                                        rcUserInfo.setUserId(orgMember.getId());
                                        JSONObject rcJson = new JSONObject();
                                        rcJson.put("year",year);
                                        rcJson.put("userId",orgMember.getId());
                                        JSONObject memberMonthJson = personalSchedule(rcJson);
                                        JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                                        rcUserInfo.setState(toDayState);
                                        rcUserInfo.setMonthInfo(monthDatas);
                                        if (ifSort){
                                            if (sortMonth.equals("Total")){
                                                JSONObject tatal = monthDatas.getJSONObject("Total");
                                                if (tatal != null && !tatal.isEmpty()){
                                                    int tatalOnSite = tatal.getInteger("onSite");
                                                    rcUserInfo.setFate(tatalOnSite);
                                                }
                                            }else{
                                                Set<String> keySet = typeMap.keySet();
                                                for (String key : keySet) {
                                                    String monthKey = typeMap.get(key);
                                                    if (sortMonth.equals(monthKey)){
                                                        JSONObject monthDate = monthDatas.getJSONObject(sortMonth);
                                                        if (monthDate != null && !monthDate.isEmpty()){
                                                            int tatalOnSite = monthDate.getInteger("onSite");
                                                            rcUserInfo.setFate(tatalOnSite);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        rcUserInfo.setState(toDayState);
                                        if (toDayState<=0){
                                            rcUserInfo.setState(2);
                                        }
                                        memberDqJa.add(rcUserInfo);
                                    }
                                }
                            }else{
                                countNum++;
                                if (!ifSort){
                                    if (countNum >= startRange && countNum <= endRange){
                                        RcUserInfo rcUserInfo = new RcUserInfo();
                                        JSONObject rcJson = new JSONObject();
                                        rcJson.put("year",year);
                                        rcJson.put("userId",orgMember.getId());
                                        rcUserInfo.setUserName(orgMember.getName());
                                        rcUserInfo.setUserId(orgMember.getId());
                                        JSONObject memberMonthJson = personalSchedule(rcJson);
                                        JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                                        rcUserInfo.setState(toDayState);
                                        rcUserInfo.setMonthInfo(monthDatas);
                                        rcUserInfo.setState(toDayState);
                                        if (toDayState<=0){
                                            rcUserInfo.setState(2);
                                        }
                                        memberDqJa.add(rcUserInfo);
                                    }
                                }else{
                                    RcUserInfo rcUserInfo = new RcUserInfo();
                                    JSONObject rcJson = new JSONObject();
                                    rcJson.put("year",year);
                                    rcJson.put("userId",orgMember.getId());
                                    rcUserInfo.setUserName(orgMember.getName());
                                    rcUserInfo.setUserId(orgMember.getId());
                                    JSONObject memberMonthJson = personalSchedule(rcJson);
                                    JSONObject monthDatas = memberMonthJson.getJSONObject("month_datas");
                                    rcUserInfo.setState(toDayState);
                                    rcUserInfo.setMonthInfo(monthDatas);
                                    if (ifSort){
                                        if (sortMonth.equals("Total")){
                                            JSONObject tatal = monthDatas.getJSONObject("Total");
                                            if (tatal != null && !tatal.isEmpty()){
                                                int tatalOnSite = tatal.getInteger("onSite");
                                                rcUserInfo.setFate(tatalOnSite);
                                            }
                                        }else{
                                            Set<String> keySet = typeMap.keySet();
                                            for (String key : keySet) {
                                                String monthKey = typeMap.get(key);
                                                if (sortMonth.equals(monthKey)){
                                                    JSONObject monthDate = monthDatas.getJSONObject(sortMonth);
                                                    if (monthDate != null && !monthDate.isEmpty()){
                                                        int tatalOnSite = monthDate.getInteger("onSite");
                                                        rcUserInfo.setFate(tatalOnSite);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    rcUserInfo.setState(toDayState);
                                    if (toDayState<=0){
                                        rcUserInfo.setState(2);
                                    }
                                    memberDqJa.add(rcUserInfo);
                                }
                            }
                        }
                    }
                }
                int startDate = startRange.intValue();
                int endDate = endRange.intValue();
                if (ifSort){
                    countNum = memberDqJa.size();
                    if (sortType==1){
                        //降序
                        List<RcUserInfo> rcUserInfos = RcMemberSortUtils.sortByFateDesc(memberDqJa);
                        List<RcUserInfo> newUserInfos = new ArrayList<RcUserInfo>();
                        for (int i = startDate; i <= endDate; i++) {
                            int rcSize = rcUserInfos.size();
                            if (i<=rcSize){
                                newUserInfos.add(rcUserInfos.get(i-1));
                            }
                        }
                        dataJson.put("userInfo", newUserInfos);
                    }else{
                        //升序
                        List<RcUserInfo> rcUserInfos = RcMemberSortUtils.sortByFateAsc(memberDqJa);
                        List<RcUserInfo> newUserInfos = new ArrayList<RcUserInfo>();
                        for (int i = startDate; i <= endDate; i++) {
                            int rcSize = rcUserInfos.size();
                            if (i<=rcSize){
                                newUserInfos.add(rcUserInfos.get(i-1));
                            }
                        }
                        dataJson.put("userInfo", newUserInfos);
                    }
                }else{
                    // List<RcUserInfo> newUserInfos = new ArrayList<RcUserInfo>();
                    // for (int i = startDate; i <= endDate; i++) {
                    //     int rcSize = memberDqJa.size();
                    //     if (i<=rcSize){
                    //         newUserInfos.add(memberDqJa.get(i-1));
                    //     }
                    // }
                    dataJson.put("userInfo", memberDqJa);
                }
                closeJdbcAgent(jdbcAgent);
            }
        }
        dataJson.put("countNum",countNum);
        return dataJson;
    }

    @Override
    public JSONObject leadershipAgenda(JSONObject param) {
        JSONObject result = new JSONObject();
        try {
            Long userId = param.getLong("userId");
            Integer year = param.getInteger("year");
            result.put("year", year);
            result.put("userId", userId);
            V3xOrgMember member = orgManager.getMemberById(userId);

            FormBean cap4FormBean = cap4FormManager.getFormByFormCode(scheduleArchiveCode);
            if(cap4FormBean != null) {
                FormFieldBean bhBean = cap4FormBean.getFieldBeanByDisplay("编号");
                FormFieldBean xmBean = cap4FormBean.getFieldBeanByDisplay("姓名");
                FormFieldBean lxBean = cap4FormBean.getFieldBeanByDisplay("类型");
                FormFieldBean ksrqBean = cap4FormBean.getFieldBeanByDisplay("开始日期");
                FormFieldBean jsrqBean = cap4FormBean.getFieldBeanByDisplay("结束日期");
                JSONObject roleJson = RcUtils.personalScheduleRoles(member.getId());
                if (roleJson != null && !roleJson.isEmpty()){
                    log.info("sss");
                }
            }else{
                log.info("动迁档案不存在！！！");
            }
        }catch (Exception e){
            log.error("领导日程异常！！！", e);
        }
        return result;
    }

    @Override
    public JSONObject personalSchedule(JSONObject param) {
        JSONObject result = new JSONObject();
        try {
            if (param == null || !param.containsKey("userId") || !param.containsKey("year")) {
                log.info("参数为空或缺少必要字段：{}"+param.toString());
                return result;
            }

            Long userId = param.getLong("userId");
            Integer year = param.getInteger("year");

            if (userId == null || year == null || year < 0) {
                log.info("无效的用户ID或年份：userId="+userId+", year="+year);
                return result;
            }

            result.put("year", year);
            result.put("userId", userId);

            V3xOrgMember member = orgManager.getMemberById(userId);
            if (member == null) {
                log.info("用户ID={}对应的成员不存在 memberId="+ userId);
                return result;
            }
            result.put("userName", member.getName());

            FormBean cap4FormBean = cap4FormManager.getFormByFormCode(scheduleArchiveCode);
            if (cap4FormBean == null) {
                log.info("动迁档案不存在");
                return result;
            }

            int[] zCounts = {0, 0, 0}; // [onSite, bt, rl]
            JSONObject month_datas = new JSONObject();
            JSONObject month_detail = new JSONObject();

            JDBCAgent jdbcAgent = getJdbcAgent();
            LocalDate today = LocalDate.now();
            LocalDate createTimeDate =null;

            Map<String, Object> properties = member.getProperties();
            Object hiredateObj = properties.get("hiredate");
            if (hiredateObj != null) {
                // 使用正则提取日期部分
                String dateStr = hiredateObj.toString().split(" ")[0];

                // 转为 LocalDate
                createTimeDate = LocalDate.parse(dateStr);
            }else{
                Date createTime = member.getCreateTime();
                createTimeDate = createTime.toInstant()
                        .atZone(ZoneId.systemDefault())
                        .toLocalDate();
            }

            for (int i = 1; i <= 12; i++) {
                JSONObject monthJson = new JSONObject();
                JSONArray all_data = new JSONArray();
                JSONArray on_site_data = new JSONArray();
                JSONArray trip_data = new JSONArray();//国际出差
                JSONArray homeTripdata = new JSONArray();//国内出差
                JSONArray leave_data = new JSONArray();
                int[] counts = {0, 0, 0}; // [onSite, bt, rl]

                List<String> allDaysInMonth = RcUtils.getAllDaysInMonth(year, i);
                if (allDaysInMonth != null && !allDaysInMonth.isEmpty()) {
                    for (String day : allDaysInMonth) {
                        LocalDate dayDate = LocalDate.parse(day, formatter);
                        // 比较两个LocalDate对象的大小
                        int comparison = today.compareTo(dayDate);
                        int comparison2 = createTimeDate.compareTo(dayDate);
                        if (comparison>=0&&comparison2<=0){
                            int rySatte = RcUtils.personalScheduleNew(day, member.getId(),jdbcAgent);
                            // int rySatte = RcUtils.personalSchedule(day, member.getId(),jdbcAgent);//未包含 国际出差 国内出差
                            switch (rySatte) {
                                case 1://国际出差
                                    trip_data.add(day);
                                    zCounts[1]++;
                                    counts[1]++;
                                    break;
                                case 2:
                                    on_site_data.add(day);
                                    zCounts[0]++;
                                    counts[0]++;
                                    break;
                                case 3:
                                    leave_data.add(day);
                                    zCounts[2]++;
                                    counts[2]++;
                                    break;
                                case 4://国内出差
                                    homeTripdata.add(day);
                                    zCounts[1]++;
                                    counts[1]++;
                                    break;
                                case 0:
                                    log.info("人员动迁状态为空，日期："+ day);
                                    on_site_data.add(day);
                                    zCounts[0]++;
                                    counts[0]++;
                                    break;
                                default:
                                    log.info("未知的人员动迁状态："+ rySatte);
                                    break;
                            }
                        }
                    }
                }

                monthJson.put("on_site_data", on_site_data);
                monthJson.put("trip_data", trip_data);
                monthJson.put("homeTrip_data", homeTripdata);
                monthJson.put("leave_data", leave_data);
                monthJson.put("all_data", all_data);
                month_detail.put(typeMap.get(String.valueOf(i)), monthJson);

                JSONObject monthDayCount = new JSONObject();
                monthDayCount.put("onSite", counts[0]);
                monthDayCount.put("bt", counts[1]);
                monthDayCount.put("rl", counts[2]);
                month_datas.put(typeMap.get(String.valueOf(i)), monthDayCount);
            }

            JSONObject total = new JSONObject();
            total.put("onSite", zCounts[0]);
            total.put("bt", zCounts[1]);
            total.put("rl", zCounts[2]);
            month_datas.put("Total", total);

            result.put("month_detail", month_detail);
            result.put("month_datas", month_datas);

            LocalDate now = LocalDate.now();
            int toDayState = RcUtils.personalSchedule(now.toString(), member.getId(),jdbcAgent);
            result.put("dayState", toDayState);

            log.info("{}--{}--数据："+ member.getName()+ year+ result.toString());
            closeJdbcAgent(jdbcAgent);
        } catch (IllegalArgumentException | NullPointerException e) {
            log.error("参数错误或空指针异常: " +e.getMessage(), e);
        } catch (Exception e) {
            log.error("发生未知异常: "+ e.getMessage(), e);
        }

        return result;
    }


    @Override
    public JSONObject employeeScheduleColumn(JSONObject param) {
        JSONObject result = new JSONObject();
        try {
            Long uaerId = param.getLong("userId");
            Integer year = param.getInteger("year");
            Integer month = param.getInteger("month");
            FormBean cap4FormBean = cap4FormManager.getFormByFormCode(scheduleArchiveCode);
            if(cap4FormBean != null){
                int onSite = 0;
                int bt = 0;
                int rl = 0;

                JDBCAgent jdbcAgent = getJdbcAgent();
                LocalDate today = LocalDate.now();

                V3xOrgMember member = orgManager.getMemberById(uaerId);
                // User currentUser = AppContext.getCurrentUser();

                result.put("userId", member.getId());
                result.put("userName", member.getName());

                JSONObject month_detail = new JSONObject();
                JSONArray all_data = new JSONArray();
                JSONArray on_site_data = new JSONArray();
                JSONArray trip_data = new JSONArray();//国际出差
                JSONArray homeTripdata = new JSONArray();//国内出差
                JSONArray leave_data = new JSONArray();

                LocalDate createTimeDate =null;
                Map<String, Object> properties = member.getProperties();
                Object hiredateObj = properties.get("hiredate");
                if (hiredateObj != null) {
                    // 使用正则提取日期部分
                    String dateStr = hiredateObj.toString().split(" ")[0];

                    // 转为 LocalDate
                    createTimeDate = LocalDate.parse(dateStr);
                }else{
                    Date createTime = member.getCreateTime();
                    createTimeDate = createTime.toInstant()
                            .atZone(ZoneId.systemDefault())
                            .toLocalDate();
                }
                List<String> allDaysInMonth = RcUtils.getAllDaysInMonth(year, month);
                if (allDaysInMonth!=null && allDaysInMonth.size()>0){
                    for (String day : allDaysInMonth){
                        LocalDate dayDate = LocalDate.parse(day, formatter);
                        // 比较两个LocalDate对象的大小
                        int comparison = today.compareTo(dayDate);
                        int comparison1 = createTimeDate.compareTo(dayDate);
                        if (comparison>=0&&comparison1<=0){
                            // int rySatte = RcUtils.personalScheduleNew(day, member.getId(),jdbcAgent);
                            int rySatte = RcUtils.personalSchedule(day, member.getId(),jdbcAgent);//原--未新增出差类型
                            if (rySatte == 1){
                                bt++;
                                trip_data.add(day);
                            } else if (rySatte == 2) {
                                onSite++;
                                on_site_data.add(day);
                            } else if (rySatte == 3) {
                                rl++;
                                leave_data.add(day);
                            } else if (rySatte == 4){
                                bt++;
                                homeTripdata.add(day);
                            }else {
                                onSite++;
                                on_site_data.add(day);
                            }
                        }
                    }
                }
                month_detail.put("all_data",all_data);
                month_detail.put("on_site_data",on_site_data);
                month_detail.put("trip_data",trip_data);
                month_detail.put("homeTrip_data", homeTripdata);
                month_detail.put("leave_data",leave_data);
                result.put("month_detail", month_detail);
                result.put("onSite", onSite);
                result.put("bt", bt);
                result.put("rl", rl);
                //获取当天的状态
                log.info("获取到"+member.getName());
                closeJdbcAgent(jdbcAgent);
            }else{
                log.info("动迁档案不存在！！！");
            }
        }catch (Exception e){
            log.error(e.getMessage(), e);
        }
        return result;
    }

    @Override
    public JSONObject leadershipAgendaColumn(JSONObject param) {
        JSONObject result = new JSONObject();
        try {
            User currentUser = AppContext.getCurrentUser();
            JSONObject roleJson = RcUtils.personalScheduleRoles(currentUser.getId());
            if(roleJson != null){
                FormBean cap4FormBean = cap4FormManager.getFormByFormCode(scheduleArchiveCode);
                if(cap4FormBean != null) {
                    int onSite = 0;
                    int bt = 0;
                    int rl = 0;

                    JDBCAgent jdbcAgent = getJdbcAgent();

                    result.put("userId", currentUser.getId());
                    result.put("userName", currentUser.getName());

                    LocalDate today = LocalDate.now();
                    Integer grade = roleJson.getInteger("grade");
                    result.put("grade", grade);
                    //所有需要查询的人
                    List<Map<String, Object>> realMembers = rcDao.getRealMembers();
                    List<V3xOrgMember> allMember= new ArrayList<>();
                    if (realMembers==null||realMembers.isEmpty()){
                        return result;
                    }else {
                        for (Map<String, Object> map : realMembers){
                            long memberId = Long.parseLong(String.valueOf(map.get("id")));
                            V3xOrgMember member = orgManager.getMemberById(memberId);
                            allMember.add(member);
                        }
                    }
                    if (grade == 1){
                        V3xOrgAccount account = orgManager.getAccountById(currentUser.getAccountId());//orgAccountId
                        Map<String,Object> depSqlMap = new HashMap<>();
                        depSqlMap.put("orgAccountId", account.getId());
                        //使用部门维护表的部门
                        List<Map<String, Object>> departments = rcDao.getAllNeedDept();
                        JSONObject depCxJson = new JSONObject();
                        JSONArray depIds = new JSONArray();
                        if (departments!=null && departments.size()>0){
                            for (Map<String, Object> department : departments){
                                Long depId = Long.valueOf(department.get("id").toString());
                                depIds.add(depId);
                            }
                        }
                        depCxJson.put("depIds", depIds);
                        depCxJson.put("dqDate", today.toString());
                        List<Map<String, Object>> allPeopleEbsRc = rcDao.getAllPeopleEbsRc(depCxJson);
                        if (allPeopleEbsRc!=null && allPeopleEbsRc.size()>0){
                            for (Map<String, Object> peopleEbsRcMap : allPeopleEbsRc){
                                Object stateObj = peopleEbsRcMap.get("state");
                                if (stateObj!=null){
                                    Object lsObj = peopleEbsRcMap.get("sl");
                                    if ("1".equals(stateObj.toString()) || "4".equals(stateObj.toString())){
                                        Integer ls = Integer.valueOf(lsObj.toString());
                                        bt=ls;
                                    }else if ("2".equals(stateObj.toString())){
                                        Integer ls = Integer.valueOf(peopleEbsRcMap.get("sl").toString());
                                        onSite = ls;
                                    } else if ("3".equals(stateObj.toString())) {
                                        Integer ls = Integer.valueOf(peopleEbsRcMap.get("sl").toString());
                                        rl = ls;
                                    }
                                }
                            }
                        }
                        //总经理---所有人员当天状态
                    }else if (grade == 2){
                        JSONArray zgDepIds = roleJson.getJSONArray("zgDepId");
                        if (zgDepIds != null){
                            JSONObject depCxJson = new JSONObject();
                            depCxJson.put("depIds", zgDepIds);
                            depCxJson.put("dqDate", today.toString());
                            List<Map<String, Object>> allPeopleEbsRc = rcDao.getAllPeopleEbsRc(depCxJson);
                            if (allPeopleEbsRc!=null && allPeopleEbsRc.size()>0){
                                for (Map<String, Object> peopleEbsRcMap : allPeopleEbsRc){
                                    Object stateObj = peopleEbsRcMap.get("state");
                                    if (stateObj!=null){
                                        Object lsObj = peopleEbsRcMap.get("sl");
                                        if ("1".equals(stateObj.toString()) || "4".equals(stateObj.toString())){
                                            Integer ls = Integer.valueOf(lsObj.toString());
                                            bt=ls;
                                        }else if ("2".equals(stateObj.toString())){
                                            Integer ls = Integer.valueOf(peopleEbsRcMap.get("sl").toString());
                                            onSite = ls;
                                        } else if ("3".equals(stateObj.toString())) {
                                            Integer ls = Integer.valueOf(peopleEbsRcMap.get("sl").toString());
                                            rl = ls;
                                        }
                                    }
                                }
                            }
                        }
                        //部门主管---主管的部门下的人员的状态
                    } else if (grade == 3) {
                        //员工
                    }
                    result.put("onSite", onSite);
                    result.put("bt", bt);
                    result.put("rl", rl);
                    closeJdbcAgent(jdbcAgent);
                }else{
                    log.info("动迁档案不存在！！！");
                }
            }
            log.info("领导栏目!!!");
        }catch (Exception e){
            log.error(e.getMessage(), e);
        }
        return result;
    }
}
